package com.netty.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import com.message.Message;
import com.netty.server.ServerNettyManager;

/**
 * server.handler
 * @author zhoufang
 *
 * 2017年12月23日下午11:23:01
 */
public class ServerChannelHandler extends SimpleChannelInboundHandler<Message>{
	
	@Override
	public void channelActive(ChannelHandlerContext ctx) throws Exception {
		super.channelActive(ctx);
		ServerNettyManager.addUnRegisterChannel(ctx.channel());
		System.err.println("server:收到channel="+ctx.channel().toString());
	}
	
	@Override
	public void channelInactive(ChannelHandlerContext ctx) throws Exception {
		super.channelInactive(ctx);
	}
	
	
	@Override
	public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
		super.channelReadComplete(ctx);
	}
	

	@Override
	protected void channelRead0(ChannelHandlerContext ctx, Message msg) throws Exception {
		System.out.println("serverHandler---"+msg.getBody().toString());
	}
	
	@Override
	public void userEventTriggered(ChannelHandlerContext ctx, Object evt)
			throws Exception {
		super.userEventTriggered(ctx, evt);
	}

}
